function getQueryString(){
     var result = location.search.match(new RegExp("[\?\&][^\?\&]+=[^\?\&]+","g")); 
     if(result == null){
         return "";
     }
     for(var i = 0; i < result.length; i++){
         result[i] = result[i].substring(1);
     }
     return result;
}

function showLogin(){
	var loginName = "";
	$.ajax({
		url:baseURL+'/api/isLogin?t='+new Date().getTime(),
		type:'GET',
		dataType:'json',
		timeout : 30000,
		contentType : "application/json; charset=utf-8",
		success : function(result) {
			 if(result.statusCode==200){
				loginName =  result.result.userName;
			 }
			 if(loginName==""){
				  $("#loginName").text("管理员登录");
				  layer_show(650,'500','登录',baseURL+'/api/login?t='+new Date().getTime());	
			  }else{
				  $("#loginName").text(loginName);
				  window.location = baseURL+"/api/main?t="+new Date().getTime();
			  }
		  }    
     });
}
$(function(){
	var engineerLabels=[],engineerDatasets=[],projectLabels=[],projectDatasets=[];
	$('.engineer_L_item').height(screen.availHeight-200+"px")
	$(".engineer_R_info_map").height(screen.availHeight-240+"px")
	$('.engineer_L_item').find("li:first").addClass("engineer_bk");
	$.Huitab("#tab_demo_1 .tabBar span","#tab_demo_1 .tabCon","current","click","0");
	$.Huitab("#tab_demo_2 .tabBar span","#tab_demo_2 .tabCon","current","click","0");
	$.ajaxSetup({
		type:"get",
		datatype:"json",
		error:function(result){
			layer.msg(result.errorMessage)
		}
	})
	$.ajax({
		url:baseURL+"/api/index/listPrjProgressSummary"+"?t="+new Date().getTime(),
		success:function(result){
			if(result.flag){
				$.each(result.results,function(i,n){
					$(".projectStatus_common").append('<li><div class="projectStatus_t">'+n.progressName+'</div><div class="projectStatus_quere"></div><div class="projectStatus_time" name="'+n.progressTypeCode+'">'+n.num+'个</div></li>')
				})
			}else layer.msg(result.message)
		}
	})
	
	$.ajax({
		url:baseURL+"/api/index/getMonthlyDataStatis"+"?t="+new Date().getTime(),
		success:function(result){
			if(result.flag){
				$.each(result.results,function(i,n){
					engineerLabels.push(n.shortTime==null?"0":n.shortTime);
					engineerDatasets.push(n.engineerAmount==null?0:n.engineerAmount);
					projectDatasets.push(n.projectAmount==null?0:n.projectAmount);
				})
				option = {
					color: ['#5cc00b'],
				    tooltip : {
			        	trigger: 'axis',
			        	axisPointer : {            // 坐标轴指示器，坐标轴触发有效
			                type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
			            }
				    },
				    toolbox: {
				        show : true,
				        right:'20px',
				        feature : {
				            saveAsImage : {show: true}
				        }
				    },
				    calculable : true,
				    xAxis : {
				            type : 'category',
				            name:'月份',
				            data : engineerLabels,
				            minInterval:1,
				            axisTick:{
				            	alignWithLabel:true
				            },
				            axisLabel:{
				            	interval:0,
				            	rotate:60
				            }
				        },
				    yAxis : [
				        {
				        	name:'新增工程师数',
				            type : 'value',
				            minInterval: 1,
				            min:0
				        }
				    ],
				    series : [
				        {
				            name:'新增工程师数',
				            type:'bar',
				            data:engineerDatasets,
				            markPoint : {
				            	label:{
				            		normal:{
				            			show:true,
				            			position:'insideTopLeft'
				            		}
				            	}
				            },
				            label:{
				            	normal:{
			            			show:true,
			            			position:'top',
			            			textStyle:{
			            				color:'#000'
			            			}
			            		}
				            }
				        }
				    ]
				};
				option_2 = {
						color: ['#5cc00b'],
					    tooltip : {
				        	trigger: 'axis',
				        	axisPointer : {            // 坐标轴指示器，坐标轴触发有效
				                type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
				            }
					    },
					    toolbox: {
					        show : true,
					        right:'20px',
					        feature : {
					            saveAsImage : {show: true}
					        }
					    },
					    calculable : true,
					    xAxis : {
					            type : 'category',
					            name:'月份',
					            data : engineerLabels,
					            minInterval:1,
					            axisTick:{
					            	alignWithLabel:true
					            },
					            axisLabel:{
					            	interval:0,
					            	rotate:60
					            }
					        },
					    yAxis : [
					        {
					        	name:'新增项目数',
					            type : 'value',
					            minInterval: 1,
					            min:0
					        }
					    ],
					    series : [
					        {
					            name:'新增项目数',
					            type:'bar',
					            data:projectDatasets,
					            markPoint : {
					            	label:{
					            		normal:{
					            			show:true,
					            			position:'insideTopLeft'
					            		}
					            	}
					            },
					            label:{
					            	normal:{
				            			show:true,
				            			position:'top',
				            			textStyle:{
				            				color:'#000'
				            			}
				            		}
					            }
					        }
					    ]
					};
                    
				var dom = document.getElementById("myChart_1");
				var myChart = echarts.init(dom);
				myChart.setOption(option);
				
				$("#tab_demo_2").find(".tabBar").find('span:last').on('click',function(e){
					var dom_2 = document.getElementById("myChart_2");
					var myChart_2 = echarts.init(dom_2);
					myChart_2.setOption(option_2);
				})
				


			}else layer.msg(result.message)
		}
	})
	
	$('.engineer_L_item').find("li").on('click',function(e){
		e.stopPropagation();
		$(e.currentTarget).addClass("engineer_bk").siblings().removeClass("engineer_bk");
		if($(e.currentTarget).attr("data-num")=="1"){
			window.location.href=baseURL+"/api/index/showEngineerPos"+"?t="+new Date().getTime();
		}else {
			window.location.href=baseURL+"/api/index/showMonthlyDatasChart?page=2&t="+new Date().getTime();
		}
	})
	var getHostURL=getQueryString();
	var pageTmp = "1";
	for(var i=0;i<getHostURL.length;i++){
		var entry = getHostURL[i];
		var startIndex = entry.indexOf("=");
		if(startIndex==-1) continue;
		var name  = entry.substring(0,startIndex);
		var value  = entry.substring(startIndex+1);
		if(name=='page'){
			pageTmp = value;
		}
	}
	
	if(pageTmp=="1"){
		$("#tab_demo_1").show();
		$("#tab_demo_2").hide();
	}else {
		$("#tab_demo_2").show();
		$("#tab_demo_1").hide();
	}
})